package jfox.platform.infrastructure;

import javax.persistence.Column;

/**
 * 支持版本记录，乐观锁的 EntityObject
 *
 * @author <a href="mailto:yang_y@sysnet.com.cn">Young Yang</a>
 */
public abstract class VersionableEntityObject extends EntityObject implements IVersionableEntityObject{

    @Column(name="VERSION")
    private int version = 0;

    public int getVersion() {
        return version;
    }

    public void setVersion(int newVersion) throws VersionOverdueException {
        if(newVersion != version + 1) {
            throw new VersionOverdueException(this.getClass(), this.getId());
        }
        this.version = newVersion;
    }

/*
    public void updateToVersion(int newVersion) throws VersionOverdueException{
        if(newVersion != version + 1) {
            throw new VersionOverdueException(this.getClass(), this.getId());
        }
        this.version = newVersion;
    }
*/

}